package com.fas.system.controller;

import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.domain.entity.SysDept;
import com.fas.common.core.page.TableDataInfo;
import com.fas.common.utils.SecurityUtils;
import com.fas.system.domain.FasInspectionGroup;
import com.fas.system.service.IFasInspectionGroupService;
import com.fas.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 巡检组 Controller
 *
 * @date 2022-07-04
 */
@Api(tags = "巡检组")
@RestController
@RequestMapping("/system/inspection/group")
public class FasInspectionGroupController extends BaseController {

    @Resource
    private IFasInspectionGroupService fasInspectionGroupService;
    @Resource
    private ISysDeptService deptService;

    @ApiOperation(value = "查询巡检组列表")
    @GetMapping("/list")
    public TableDataInfo queryAll(FasInspectionGroup fasInspectionGroup,Integer pageNum,Integer pageSize){
        Long deptId = SecurityUtils.getDeptId();
        SysDept sysDept = deptService.selectDeptById(deptId);
        String deptType = sysDept.getDeptType();
        if (deptType.equals("1") || deptType.equals("2")){
            //单位不是总公司的查询本单位下的数据
            if(fasInspectionGroup.getDeptId() == null){
                fasInspectionGroup.setDeptId(deptId.intValue());
            }
        }
        startPage();
        return getDataTable(fasInspectionGroupService.queryAll(fasInspectionGroup));
    }
    @ApiOperation(value = "查询巡检组详细信息")
    @GetMapping("/findById/{groupCode}")
    public AjaxResult findById(@PathVariable Integer groupCode){
        return  AjaxResult.success(fasInspectionGroupService.findById(groupCode));
    }

    @ApiOperation(value = "增加巡检组")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FasInspectionGroup fasInspectionGroup){
        Long deptId = SecurityUtils.getDeptId();
        fasInspectionGroup.setDeptId(deptId.intValue());
        return toAjax(fasInspectionGroupService.insertFasInspectionGroup(fasInspectionGroup));
    }

    @ApiOperation(value = "修改巡检组")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FasInspectionGroup fasInspectionGroup){
        return toAjax(fasInspectionGroupService.updateFasInspectionGroup(fasInspectionGroup));
    }

    @ApiOperation(value = "删除巡检组")
    @DeleteMapping("/delete/{groupCodes}")
    public AjaxResult delete(@PathVariable Integer[] groupCodes){
        return toAjax(fasInspectionGroupService.deleteFasInspectionGroup(groupCodes));
    }

    @ApiOperation(value = "巡检组-巡检组详情-添加组员")
    @GetMapping("/findXCUsersPage")
    public TableDataInfo findXCUsersPage(Integer pageNum,Integer pageSize,Integer groupCode,String userName,String phoneNumber,String iName){
        Long deptId = SecurityUtils.getDeptId();
        startPage();
        return getDataTable(fasInspectionGroupService.findXCUsersPage(deptId.intValue(), groupCode,userName,phoneNumber,iName));
    }



}
